﻿using System;
using System.Collections.Generic;

namespace com.nm.interfaces
{
    public interface IConfigurationFactory : IFactory
    {
        /// <summary>
        /// 命名空间
        /// </summary>
        string NameSpace { get; set; }

        /// <summary>
        /// 返回所有的可用键值
        /// </summary>
        IEnumerable<string> AllKey { get; }

        /// <summary>
        /// 得到字符串形式的配置值（就是把值转换成字符串）
        /// </summary>
        /// <param name="pKey"></param>
        /// <returns></returns>
        string GetValue(string pKey);

        /// <summary>
        /// 设置配置值
        /// 必须是已经存在的 否则设置不成功
        /// </summary>
        /// <param name="pKey"></param>
        /// <param name="pValue"></param>
        /// <returns></returns>
        IConfigurationFactory SetConfig(string pKey, string pValue);

        #region Get

        /// <summary>
        /// 获取配置值，如果值不存在则自动创建
        /// </summary>
        /// <param name="pKey"></param>
        /// <param name="pValue"></param>
        /// <returns></returns>
        int Get(string pKey, int pValue);

        /// <summary>
        /// 获取配置值，如果值不存在则自动创建
        /// </summary>
        /// <param name="pKey"></param>
        /// <param name="pValue"></param>
        /// <returns></returns>
        long Get(string pKey, long pValue);

        /// <summary>
        /// 获取配置值，如果值不存在则自动创建
        /// </summary>
        /// <param name="pKey"></param>
        /// <param name="pValue"></param>
        /// <returns></returns>
        double Get(string pKey, double pValue);

        /// <summary>
        /// 获取配置值，如果值不存在则自动创建
        /// </summary>
        /// <param name="pKey"></param>
        /// <param name="pValue"></param>
        /// <returns></returns>
        decimal Get(string pKey, decimal pValue);

        /// <summary>
        /// 获取配置值，如果值不存在则自动创建
        /// </summary>
        /// <param name="pKey"></param>
        /// <param name="pValue"></param>
        /// <returns></returns>
        DateTime Get(string pKey, DateTime pValue);

        /// <summary>
        /// 获取配置值，如果值不存在则自动创建
        /// </summary>
        /// <param name="pKey"></param>
        /// <param name="pValue"></param>
        /// <returns></returns>
        bool Get(string pKey, bool pValue);

        /// <summary>
        /// 获取配置值，如果值不存在则自动创建
        /// </summary>
        /// <param name="pKey"></param>
        /// <param name="pValue"></param>
        /// <returns></returns>
        string Get(string pKey, string pValue);

        /// <summary>
        /// 获取配置值，如果值不存在则自动创建
        /// </summary>
        /// <typeparam name="T">可实例化的类</typeparam>
        /// <param name="pKey"></param>
        /// <param name="pValue"></param>
        /// <returns></returns>
        T Get<T>(string pKey, T pValue) where T : class, new();

        #endregion Get

        #region Set

        /// <summary>
        /// 设置配置值，如果已经存在则会覆盖
        /// 如果已经存在值且类型不符合则会抛出异常
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="pKey"></param>
        /// <param name="pValue"></param>
        /// <returns></returns>
        IConfigurationFactory Set<T>(string pKey, T pValue) where T : class, new();

        /// <summary>
        /// 设置配置值，如果已经存在则会覆盖
        /// 如果已经存在值且类型不符合则会抛出异常
        /// </summary>
        /// <param name="pKey"></param>
        /// <param name="pValue"></param>
        /// <returns></returns>
        IConfigurationFactory Set(string pKey, int pValue);

        /// <summary>
        /// 设置配置值，如果已经存在则会覆盖
        /// 如果已经存在值且类型不符合则会抛出异常
        /// </summary>
        /// <param name="pKey"></param>
        /// <param name="pValue"></param>
        /// <returns></returns>
        IConfigurationFactory Set(string pKey, long pValue);

        /// <summary>
        /// 设置配置值，如果已经存在则会覆盖
        /// 如果已经存在值且类型不符合则会抛出异常
        /// </summary>
        /// <param name="pKey"></param>
        /// <param name="pValue"></param>
        /// <returns></returns>
        IConfigurationFactory Set(string pKey, decimal pValue);

        /// <summary>
        /// 设置配置值，如果已经存在则会覆盖
        /// 如果已经存在值且类型不符合则会抛出异常
        /// </summary>
        /// <param name="pKey"></param>
        /// <param name="pValue"></param>
        /// <returns></returns>
        IConfigurationFactory Set(string pKey, bool pValue);

        /// <summary>
        /// 设置配置值，如果已经存在则会覆盖
        /// 如果已经存在值且类型不符合则会抛出异常
        /// </summary>
        /// <param name="pKey"></param>
        /// <param name="pValue"></param>
        /// <returns></returns>
        IConfigurationFactory Set(string pKey, DateTime pValue);

        /// <summary>
        /// 设置配置值，如果已经存在则会覆盖
        /// 如果已经存在值且类型不符合则会抛出异常
        /// </summary>
        /// <param name="pKey"></param>
        /// <param name="pValue"></param>
        /// <returns></returns>
        IConfigurationFactory Set(string pKey, double pValue);

        #endregion Set
    }
}